package come.bjpowernode.javase.io;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/*
使用FileReader和FileWriter进行拷贝的话，只能拷贝普通文本文件。

 */
public class Copy02 {
    public static void main(String[] args) {
        FileReader in = null;
        FileWriter out = null;

        try {
            //读
            in = new FileReader("chapter23/src/come/bjpowernode/javase/io/Copy02.java");
            //写
            out = new FileWriter("readerFile");

            //一边读，一边写
            char[] chars = new char[1024 * 512];//char占连个字节，所以chars大小为1M
            int readCount = 0;
            while((readCount = in.read(chars))!=-1){
                out.write(chars,0,readCount);
            }
            //输出刷新
            out.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if(in != null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(out != null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
